package cz.none.bezbarier.web.repository.impl;

import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;

import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;

import cz.none.bezbarier.web.model.Place;
import cz.none.bezbarier.web.model.Type;
import cz.none.bezbarier.web.repository.PlaceRepositoryCustom;
import cz.none.bezbarier.web.util.Constants;

public class PlaceRepositoryImpl extends ARepository<Place> implements PlaceRepositoryCustom {

	@PersistenceContext
	private EntityManager em;

	@Override
	public Page<Place> findByType(Type type, Pageable pageable) {
		return this.findByQuery(Constants.SQL.PLACE_TYPE_SELECT, Constants.SQL.PLACE_TYPE_COUNT, Place.class,
				pageable, type);
	}

	@Override
	public Page<Place> findByName(String name, Pageable pageable) {
		return this.findByQuery(Constants.SQL.PLACE_NAME_SELECT, Constants.SQL.PLACE_NAME_COUNT, Place.class,
				pageable, name, name + "\ufffd");
	}

	@Override
	public Page<Place> findByTypeAndName(Type type, String name, Pageable pageable) {
		return this.findByQuery(Constants.SQL.PLACE_TYPE_NAME_SELECT, Constants.SQL.PLACE_TYPE_NAME_COUNT,
				Place.class, pageable, type, name, name + "\ufffd");
	}

}
